package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.User;
import com.zr.service.Tjsqservice;
import com.zr.serviceImpl.TjsqserviceImpl;

import net.sf.json.JSONArray;

public class TjsqController extends HttpServlet{
             Tjsqservice t=new TjsqserviceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		    resp.setCharacterEncoding("utf-8");
		    req.setCharacterEncoding("utf-8");
	        String edata= req.getParameter("edata");
	        String etartday=  req.getParameter("etartday");
	        int actualday=Integer.parseInt(req.getParameter("actualday"));
	        String category = req.getParameter("category");
	         String reason=req.getParameter("reason");
	        String opinion=req.getParameter("opinion");
	        String remake= req.getParameter("remake");
	        String state=req.getParameter("state");
	        String ename=req.getParameter("ename");
	        HttpSession session=req.getSession();
	         User u=(User) session.getAttribute("user");
	        	  PrintWriter pw=resp.getWriter();
		        
		            SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy-MM-dd" );
		            String date=sdf.format(new Date());
		     
		            String data=t.findtj(u.getUsernum());
				   if(date.equals(data)){
		            	pw.write("0");
		            }else{
		            	 boolean b=  t.findtjsq(date, etartday, actualday, category, reason, opinion,u.getUsernum(), remake,state);
		            	   if(b){
		      	        	 pw.write("1");
		      	         }else{
		      	        	 pw.write("0");
		      	         }
		            }
		  
	        
	         
	  
	         
	
	}
  
}
